﻿Module ModuloParse
    Public tlen As Double
    Public temp As Double
    Public i As Double
    Public substr As String
    Public Function string_parse_single(ByVal str As String, ByVal token As Char, ByVal N As Double, ByVal ignore As Boolean) As String
        '/*
        '**      string_parse_single(str,token,N,ignore_null)
        '**  Example:
        '**      string_parse_single("cat|dog|house|bee", "|", 2, true);
        '**      returns "dog"
        '*/
        '{
        'var str, token, substr, ignore, N, tlen, temp, i;

        'str = argument0;
        'token = argument1;
        'N = argument2;
        'ignore = argument3;

        'tlen = string_length( token);

        tlen = 1
        'str.
        substr = ""
        i = 0
        While str.Length <> 0 And i < N
            'temp = string_pos( token, str);
            temp = str.IndexOf(token)
            'temp = str.Split(
            If temp Then

                If temp <> 1 Or ignore = False Then
                    'substr = string_copy(str, 1, temp - 1);
                    substr = str.Substring(0, temp)
                    i += 1
                End If
                'str = string_copy( str, temp + tlen, string_length( str));
                str = str.Substring(temp + 1, str.Length - (temp + 1))
            Else
                substr = str
                i += 1
                str = ""
            End If
        End While

        If i <> N Then
            Return ""
        Else
            Return substr
        End If


    End Function
End Module
